-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Add std::process::exit #1011
Conversation
Add a new function to the `std::process` module to exit the process immediately with a specified exit code.
[win]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682658%28v=vs.85%29.aspx | ||
|
||
This function is also not marked `unsafe`, despite the risk of leaking | ||
allocated resources (e.g. destructor smany not be run). It is already possible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/destructor smany/destructors may/
|
||
* To what degree should the documentation imply that `rt::at_exit` handlers are | ||
run? Implementation-wise their execution is guaranteed, but we may not wish | ||
for this to always be so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should guarantee it. If we wish to make this not necessarily be true in the future, then I think that calls for adding a second function that explicitly bypasses rt::at_exit
(and consequently is marked unsafe
).
I'm sympathetic to the idea that we should let |
👍, although I find it mildly odd to put this in |
This is a good point, and I feel the same way! I'll add some text related to this in the RFC.
Our plan is to expand the module to also allow inspection of remote processes, sending signals, etc. In that sense it may not always be specifically about child processes. I also consider |
yes please |
Since we’re adding a function for this (yay), we should also guarantee EDIT: |
that status (e.g. Rust was called from C). | ||
|
||
The purpose of this RFC is to provide at least one method on the path to | ||
stabilization which will provide a method to exit a process with a nonzero exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/a nonzero/an arbitrary/, or, perhaps, there’s any reason why calling exit(0)
is invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes this is definitely meant to allow exit(0)
, just botched the wording ab it.
@nagisa yeah I'm not quite sure how to word the documentation given that |
Hmm, there's another major motivation for this that I can think of, which is ending the process without risking unwinding across an FFI boundary, e.g. in a Rust function that has been passed to a C library as a callback. IIRC, unwinding past an FFI boundary is undefined behavior, but we don't have a very solid recommendation for what you should actually do if you need to terminate the process and a foreign function is (or may be) on the stack. About the only thing that you can do to prevent this right now is either call the Edit: I guess that the RFC obliquely mentions this. I guess my point is that this would be a reasonable justification for having an |
This commit is an implementation of [RFC rust-lang#1011][rfc] which adds an `exit` function to the standard library for immediately terminating the current process with a specified exit code. [rfc]: rust-lang/rfcs#1011
This was discussed at today's meeting which echoed the support found on this RFC thread. This API is clearly important to provide in some form, and there's little question as to its API. Landing it now will make it possible to yield an exit code without having to stabilize the problematic |
This commit is an implementation of [RFC rust-lang#1011][rfc] which adds an `exit` function to the standard library for immediately terminating the current process with a specified exit code. [rfc]: rust-lang/rfcs#1011 Closes rust-lang#23914
Add a new function to the
std::process
module to exit the process immediatelywith a specified exit code.
Rendered